package com.sscw.tcp.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.sscw.tcp.entity.GRecordGamePO;
import com.sscw.tcp.mapper.GRecordGameExtMapper;
import com.sscw.tcp.mapper.GRecordGameMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;

@Repository
@AllArgsConstructor
public class GRecordGameDAO extends BaseDAO<GRecordGameMapper, GRecordGamePO> {

    private final GRecordGameExtMapper gRecordGameExtMapper;

    public GRecordGamePO findRoomPlaying(Long roomId, String positionNo) {
        LambdaQueryWrapper<GRecordGamePO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.and(wrapper -> wrapper.isNull(GRecordGamePO::getEndTime).or().ge(GRecordGamePO::getEndTime, LocalDateTime.now()));
        queryWrapper.eq(GRecordGamePO::getRoomId, roomId);
        queryWrapper.eq(GRecordGamePO::getPositionNo, positionNo);
        return getBaseMapper().selectOne(queryWrapper);
    }

    public int updateData(Long id, Integer usePinecone, Integer getPineNut, LocalDateTime finallyCoinTime) {
        return gRecordGameExtMapper.updateData(id, usePinecone, getPineNut, finallyCoinTime);
    }
}
